package com.ruoyi.system.utils;

import org.iherus.codegen.qrcode.QrcodeGenerator;
import org.iherus.codegen.qrcode.SimpleQrcodeGenerator;
import org.springframework.stereotype.Component;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;

/**
 * 二维码生成工具类
 *
 * @author ruoyi
 */
@Component
public class QrCodeUtils {





    public static void testGetImage(String content, HttpServletResponse response) throws IOException {

        try{
            QrcodeGenerator generator = new SimpleQrcodeGenerator();
            OutputStream out = response.getOutputStream();
            BufferedImage image = generator.generate(content).getImage();
            ImageIO.write(image, "png", out);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
